/*
 * Copyright (c) 2016- 2020 qolome.com Inc. All Rights Reserved.
 * ProjectName: qolome-knowledge
 * FileName: Leaf.java
 * Author: jiangfeng@qolome.com
 * Date: 2020/3/10 下午11:49
 * LastModified: 2020/03/10 23:49:10
 */

package com.qolome.knowledge.design.pattern.composite.general.transparent;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Qolome
 * @version V1.0
 * @Description 组合
 * @date 2020年 03月10日 23:49:02
 */
public class Composite extends Component{

    private List<Component> components;

    public  Composite(String name){
        super(name);
        this.components = new ArrayList<>();
    }

    @Override
    public String operation() {
        StringBuilder builder = new StringBuilder(this.name);
        for (Component component: this.components
             ) {
            builder.append("\n");
            builder.append(component.operation());
        }
        return builder.toString();
    }

    @Override
    boolean addChild(Component component){
        throw new UnsupportedOperationException("addChild not support!");
    }
    @Override
    boolean removeChild(Component component){
        throw new UnsupportedOperationException("removeChild not support!");
    }
    @Override
    Component getChild(int index){
        throw new UnsupportedOperationException("getChild not support!");
    }
}
